import { User } from "../../../modeal/user.js"
const user = new User()
Page({
  data: {

  },


  login () {
    this.getToken()
  },

  getToken () {
    wx.login({
      success: res => {
        user.getToken(res.code).then(res => {
          wx.setStorageSync("token", res);
          wx.navigateBack({
            delta: 1
          })
          this.checkToken(res)
        })
      }
    })
  },
  // 检测token 有效期
  checkToken (token) {
    user.indateToken(token).then(res => {
      wx.setStorageSync("userinfo", res)
      if (!res.mobile) {
        wx.showModal({
          title: '注册提示',
          content: '注册后可以获得注册优惠券,节日优惠券！',
          showCancel: false,
          // success: res => {
          //   if (res.confirm) {
          //     wx.navigateTo({
          //       url: "/pages/user/register/register"
          //     })
          //   }
          // }
        });
      }
    })
  }
})